#ifndef ENERGY_H
#define ENERGY_H

class Energy{
	
public:
		
	double kin0, kin1, kin;
	double pot0, pot1, pot;
	double tot0, tot1, tot;
	double      dtot1,dtot, dtot1r,dtotr;
	bool fistTime;
		
	Energy():fistTime(true){}
		
	void calc(uint N, double *m, double*v0,double*v1,double*v2, double *_pot) {
			
		pot1=pot;
		kin1=kin;
		tot1=tot;
			
		kin=pot=0;
			
		for (uint i=0; i<N; i++) {
			pot+=_pot[i];
			kin+=m[i]*(SQR(v0[i])+SQR(v1[i])+SQR(v2[i]));
		}
			
		pot*=0.5;
		kin*=0.5;
		tot=kin+pot;
			
		if (fistTime) {
			pot0=pot;
			kin0=kin;
			tot0=tot;
			fistTime=false;
		}

		dtot=tot-tot0;
		dtotr=(tot-tot0)/tot0;
			
		dtot1=tot-tot1;
		dtot1r=(tot-tot1)/tot1;
			
	};
		
};
	


#endif